﻿using CSharpDay16__WebAPI_.Data.Model;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpDay16__WebAPI_.Data.Migrations
{
    public static class Seeder
    {
        public static void Seed(ApplicationDbContext db, bool roles = true, bool users = true, bool superpeople = true)
        {
            if (roles) SeedRoles(db);
            if (users) SeedUsers(db);
            if (superpeople) SeedSupers(db);
        }

        private static void SeedRoles(ApplicationDbContext db)
        {
            var manager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db));

            if (!manager.RoleExists(Roles.User)) manager.Create(new IdentityRole(Roles.User));
            if (!manager.RoleExists(Roles.Admin)) manager.Create(new IdentityRole(Roles.Admin));
            if (!manager.RoleExists(Roles.Hero)) manager.Create(new IdentityRole(Roles.Hero));
            if (!manager.RoleExists(Roles.Villain)) manager.Create(new IdentityRole(Roles.Villain));
        }

        private static void SeedUsers(ApplicationDbContext db)
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));

            if (!db.Users.Any(x => x.UserName == "superman@hero.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    UserName = "superman@hero.com",
                    Email = "superman@hero.com"
                };
                manager.Create(user, "123123");
                manager.AddToRoles(user.Id, Roles.User, Roles.Hero);
            }
            if (!db.Users.Any(x => x.UserName == "lexLuthor@villain.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    UserName = "lexLuthor@villain.com",
                    Email = "lexLuthor@villain.com"
                };
                manager.Create(user, "123123");
                manager.AddToRoles(user.Id, Roles.User, Roles.Villain);
            }
            if (!db.Users.Any(x => x.UserName == "admin@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    UserName = "admin@test.com",
                    Email = "admin@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRoles(user.Id, Roles.Admin);
            }
        }

        private static void SeedSupers(ApplicationDbContext db)
        {
            db.SuperPeople.AddOrUpdate(x => x.Id,
                new SuperPerson() { Id = 1, Name = "Superman", IsEvil = false, ImageUrl = "http://thelistlove.com.gridhosted.co.uk/wp-content/uploads/2014/06/162.jpg", Description = "Polaroid Etsy street art, pickled flexitarian Tumblr yr sartorial McSweeney's bicycle rights mlkshk disrupt sustainable shabby chic salvia. Keffiyeh twee typewriter street art lomo messenger bag, chillwave mlkshk. Lomo 3 wolf moon bitters jean shorts. Pour-over forage listicle squid hoodie. Banksy sartorial blog, Pitchfork vinyl pour-over bicycle rights High Life lo-fi gastropub pork belly drinking vinegar narwhal. Cliche yr fap Etsy tote bag, master cleanse Marfa mixtape Thundercats tousled synth Truffaut art party migas. VHS DIY artisan fashion axe trust fund PBR&B, literally squid try-hard next level crucifix kogi PBR twee." },
                new SuperPerson() { Id = 2, Name = "Batman", IsEvil = false, ImageUrl = "http://static.comicvine.com/uploads/original/11112/111123678/3503035-3468468-2718720139-batma.jpg", Description = "Helvetica mumblecore direct trade Bushwick PBR&B salvia. Viral dreamcatcher mustache, meditation Echo Park mumblecore hoodie VHS fingerstache squid DIY typewriter. +1 flexitarian taxidermy freegan trust fund, lomo mlkshk VHS gastropub ugh fanny pack fingerstache raw denim. Meh lumbersexual skateboard lomo, stumptown taxidermy heirloom occupy sustainable leggings mustache Brooklyn High Life dreamcatcher. High Life gluten-free migas keytar tote bag, gentrify listicle dreamcatcher raw denim mustache plaid hashtag squid aesthetic selfies. Gastropub meggings gluten-free American Apparel asymmetrical, next level artisan biodiesel. Biodiesel ugh wolf, pickled tousled post-ironic hoodie Pitchfork PBR&B synth." },
                new SuperPerson() { Id = 3, Name = "Goku", IsEvil = false, ImageUrl = "http://static.comicvine.com/uploads/original/14/149746/3517421-2463973295-Goku_.jpg", Description = "Asymmetrical fixie stumptown butcher. Neutra four dollar toast Echo Park, hoodie tote bag Helvetica PBR flannel letterpress disrupt vinyl 8-bit gluten-free Truffaut. Tousled four loko Helvetica Brooklyn, umami vegan salvia DIY flexitarian direct trade Kickstarter. Selfies narwhal cray cornhole Helvetica flexitarian paleo, raw denim four dollar toast polaroid gastropub Vice viral beard kitsch. Irony keffiyeh master cleanse, listicle bitters skateboard selvage asymmetrical food truck mumblecore cornhole slow-carb. Blog locavore ugh Bushwick. Letterpress PBR&B distillery, meh wolf Blue Bottle salvia sriracha." },
                new SuperPerson() { Id = 4, Name = "Lex Luthor", IsEvil = true, ImageUrl = "http://static.comicvine.com/uploads/ignore_jpg_scale_small/3/36427/832868-lex_luthor.jpg", Description = "Ugh literally Banksy, Neutra yr synth farm-to-table flexitarian. Keytar before they sold out disrupt, cray stumptown distillery Wes Anderson four loko irony Thundercats. Thundercats typewriter food truck sriracha four dollar toast, craft beer freegan. Wes Anderson tousled Pinterest Odd Future High Life single-origin coffee, mumblecore whatever twee seitan kitsch cred. Church-key PBR Portland normcore semiotics, disrupt cold-pressed. Semiotics chillwave tote bag, cray ugh stumptown VHS gluten-free sriracha 3 wolf moon YOLO High Life. Brooklyn fap sriracha Banksy pop-up health goth." },
                new SuperPerson() { Id = 5, Name = "The Joker", IsEvil = true, ImageUrl = "http://llmckinney.com/wp-content/uploads/2013/03/joker-the-joker-9028188-1024-768.jpg", Description = "Fixie irony heirloom, wolf YOLO migas Portland Helvetica single-origin coffee mumblecore salvia church-key mlkshk. Master cleanse normcore small batch tousled, leggings fixie banjo Marfa. Four loko Carles salvia, bitters four dollar toast whatever seitan biodiesel banjo quinoa artisan iPhone umami. +1 butcher messenger bag retro tousled health goth, artisan before they sold out slow-carb YOLO whatever. Deep v chillwave gluten-free migas hashtag. Wolf Carles deep v Tumblr, bespoke Williamsburg fingerstache. 3 wolf moon tofu forage, Odd Future narwhal irony Kickstarter health goth roof party cred tousled Shoreditch Pinterest meh selvage." }
                );
        }
    }
}